package components.views.filters.time
{
	import components.views.filters.events.FilterEvent;
	
	import flash.events.MouseEvent;
	
	import flexlib.controls.HSlider;
	
	import mx.containers.HBox;
	import mx.controls.CheckBox;
	import mx.events.SliderEvent;

	[Event(name="TIME_FILTER", source="components.views.filters.events.FilterEvent")]

	public class TimeSlider extends HBox
	{
		// --------------- UI Components -------------- //
		private var slider:HSlider;
		private var checkbox:CheckBox;
		// --------------- END UI Components -------------- //
		
		// -------------------- Initialization -------------------- //
		public function TimeSlider()
		{
			super();
			
			initComponents();
		}
		
		private function initComponents():void
		{
			this.removeAllChildren();
			
			slider = new HSlider();
			slider.percentWidth = 100;
			slider.allowThumbOverlap = false;
			slider.allowTrackClick = true;
			slider.liveDragging = false;
			slider.showDataTip = true;
			slider.dataTipFormatFunction = formatTimeData;
			slider.thumbCount = 2;
			slider.lockRegionsWhileDragging = true;
			slider.minimum = 8;
			slider.maximum = 22;
			
			slider.values = [8, 22];
			slider.addEventListener(SliderEvent.CHANGE, onSliderMove);
			slider.addEventListener(SliderEvent.THUMB_RELEASE, onSliderMove);
			this.addChild(slider);
			
			checkbox = new CheckBox();
			checkbox.label = "Unavailable";
			checkbox.addEventListener(MouseEvent.CLICK, onCheckChange);
			this.addChild(checkbox);
		}
		// -------------------- END Initialization -------------------- //
		
		private function formatTimeData(item:Object):String
		{
			return "DataTip";	
		}
		
		public function reset():void
		{
			initComponents();
		}
		
		// ---------------- Event Handling ------------------ //
		private function onCheckChange(evt:MouseEvent):void
		{
			this.dispatchEvent(new FilterEvent(FilterEvent.TIME_FILTER, true));
		}
		
		private function onSliderMove(evt:SliderEvent):void
		{
			this.dispatchEvent(new FilterEvent(FilterEvent.TIME_FILTER, true));
		}
		// ---------------- END Event Handling ------------------ //
	}
}